package com.zhihao.takeaway.common.exception;

import com.zhihao.takeaway.common.utils.Result;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLIntegrityConstraintViolationException;

@ControllerAdvice
public class SQLException {
    @ExceptionHandler(DataAccessException.class)
    @ResponseBody
    public Result SQLViolation(SQLIntegrityConstraintViolationException sQLIntegrityConstraintViolationException){
        Result result  =new Result();
        result.setStatusCode("404");
        result.setMessage("添加失败，信息已存在");
        return result;
    }
}
